import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1, 1, 201)
yt = []
for t in x:
    yx = 1 / (1 + 25 * t * t)
    yt.append(yx)

N = [6, 11, 21, 41, 81]

# Plot for ppForm
plt.figure()
filename = "data/proAppForm.txt"
with open(filename, 'r') as f:
    lines = f.readlines()

plt.plot(x, yt, label = "y = f(x)")

for i in range(len(N)):
    y = [float(s) for s in lines[i].split()]
    plt.plot(x, y, label = "N = " + str(N[i]), linestyle = "--")
plt.xlabel("x")
plt.ylabel("y")
plt.title("Use ppForm to interpolate f(x) with different knots.")
plt.legend()

figurename = "../report/figure/proAppForm.png"
plt.savefig(figurename)


# Plot for Bspline
plt.figure()
filename = "data/proABspline.txt"
with open(filename, 'r') as f:
    lines = f.readlines()

plt.plot(x, yt, label = "y = f(x)")

for i in range(len(N)):
    y = [float(s) for s in lines[i].split()]
    plt.plot(x, y, label = "N = " + str(N[i]), linestyle = "--")
plt.xlabel("x")
plt.ylabel("y")
plt.title("Use Bspine to interpolate f(x) with different knots.")
plt.legend()

figurename = "../report/figure/proABspline.png"
plt.savefig(figurename)

print("Finish ploting for Pro A.")